﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Leffaetsin.Models;
using RestSharp;

namespace Leffaetsin.Services.Providers.ShowProviders
{
    internal class BioRexProvider : AbstractShowProvider
    {
        public override IEnumerable<GetMovieDto> GetShows(string areaName)
        {
            var areaId = "";
            switch (areaName.ToLowerInvariant())
            {
                case "espoo":
                case "pääkaupunkiseutu":
                    areaId = "1001";
                    break;
                case "kajaani":
                    areaId = "1005";
                    break;
                case "hämeenlinna":
                    areaId = "1004";
                    break;
                case "porvoo":
                    areaId = "1007";
                    break;
                default:
                    return Enumerable.Empty<BiorexShow>();
            }

            var client = new RestClient("http://83.145.218.108/");
            var request = new RestRequest("rss/xml/schedule/?areaId=" + areaId, Method.GET);

            IRestResponse<BiorexShows> finnkinoMovies = client.Execute<BiorexShows>(request);

            // TODO: better error handling, kirjota lokiin tms!
            return finnkinoMovies.Data == null ? Enumerable.Empty<BiorexShow>() : finnkinoMovies.Data.Shows;
        }

        public override IEnumerable<TheatreArea> GetAreas()
        {
            return new List<TheatreArea>()
                       {
                           new TheatreArea()
                               {
                                   ID = "1001",
                                   Name = "Espoo"
                               },
                               new TheatreArea()
                               {
                                   ID = "1004",
                                   Name = "Hämeenlinna"
                               },
                               new TheatreArea()
                               {
                                   ID = "1005",
                                   Name = "Kajaani"
                               },
                               new TheatreArea()
                               {
                                   ID = "1007",
                                   Name = "Porvoo"
                               },
                       };
        }
    }
}